
<?php
 
/*
 * Following code will get single product details
 * A product is identified by product id (pid)
 */
 
// array for JSON response
$response = array();

// definiton


//define('TABLE', "JOKE"); // db user
 
// include db connect class
require_once ('connect.php');
require_once ('build_object.php');
 
// connecting to db
$db = new CONNECT();
 
// check for post data

 
 $str_query = getQueryString();
 
    // get a product from products table

	
	$debug = 	$_GET['DEBUG'];
	
	if($debug==1){
		echo "<br> [query:] $str_query <br>";
	}
	
    $result = mysql_query("$str_query");
 
    if (!empty($result)) {
        // check for empty result

		
		
        if (mysql_num_rows($result) > 0) {
 
            //$result = mysql_fetch_array($result);
			$table 				= $_GET['TABLE'];
			$response["$table"] = array();
 
			while ($row = mysql_fetch_array($result)) {
			// temp user array
			
				
				

				
				$product = array();
				$product 			= buildObject($table,$row);
				
 
				array_push($response["$table"], $product);
			}


            // success
            $response["success"] = 1;
 
            // user node

 
            // echoing JSON response
            echo json_encode($response);
        } else {
            // no product found
            $response["success"] = 0;
            $response["message"] = "No product found";
 
            // echo no users JSON
            echo json_encode($response);
        }
    } else {
        // no product found
        $response["success"] = 0;
        $response["message"] = "No product found";
 
        // echo no users JSON
        echo json_encode($response);
    }




function getQueryString(){

	$table = 	$_GET['TABLE'];
    $column = 	$_GET['COLUMN'];
	$value = 	$_GET['VALUE'];
	$cid	=   $_GET['CID'];
	
	
	if($column == "ALL"){
		$str_query = "SELECT *FROM $table WHERE ID > '$cid' LIMIT 8";
	}else{
		$str_query = "SELECT *FROM $table WHERE $column = '$value' && ID > '$cid' LIMIT 8";
	}
	
	
	return $str_query;


}





?>